﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace TinyToolKit.Demo
{
    public class Player : MonoBehaviour
    {
        public float speed = 5;
        public float smooth = 5;

        private float oriSpeed;
        private CharacterController characherCon;

        private void Start()
        {
            characherCon = gameObject.GetComponent<CharacterController>();
            if (characherCon == null)
                characherCon = gameObject.AddComponent<CharacterController>();

            oriSpeed = speed;
        }

        private void Update()
        {
            float h = Input.GetAxis("Horizontal");
            float v = Input.GetAxis("Vertical");

            transform.Rotate(Vector3.up, h * smooth);
            characherCon.SimpleMove(transform.forward * v * speed);

            if (Input.GetKeyDown(KeyCode.Space))
            {
                speed = oriSpeed * 2;
            }
            
            if (Input.GetKeyUp(KeyCode.Space))
            {
                speed = oriSpeed;
            }

            if (Input.GetKeyDown(KeyCode.R))
            {
                UnityEngine.SceneManagement.SceneManager.LoadScene(0);
            }
        }
    }
}
